package com.qckj.amz.controller;

import com.qckj.amz.domain.PersonalTranslate;
import com.qckj.amz.service.IPersonalTranslateService;
import com.qckj.common.annotation.Log;
import com.qckj.common.core.controller.BaseController;
import com.qckj.common.core.domain.AjaxResult;
import com.qckj.common.core.page.TableDataInfo;
import com.qckj.common.enums.BusinessType;
import com.qckj.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 翻译工具Controller
 *
 * @author luchuan
 * @since 1.0 2022-07-28
 */
@RestController
@RequestMapping("/amz/personalTranslate")
public class PersonalTranslateController extends BaseController {
    @Autowired
    private IPersonalTranslateService personalTranslateService;

    /**
     * 查询翻译工具列表
     */
    @PreAuthorize("@ss.hasPermi('amz:personalTranslate:list')")
    @GetMapping("/list")
    public TableDataInfo list(PersonalTranslate personalTranslate) {
        Page<PersonalTranslate> page = personalTranslateService.findPersonalTranslatePage(personalTranslate);
        return getDataTable(page);
    }

    /**
     * 导出翻译工具列表
     */
    @PreAuthorize("@ss.hasPermi('amz:personalTranslate:export')")
    @Log(title = "翻译工具", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PersonalTranslate personalTranslate) {
        List<PersonalTranslate> list = personalTranslateService.findPersonalTranslateList(personalTranslate);
        ExcelUtil<PersonalTranslate> util = new ExcelUtil<>(PersonalTranslate.class);
        return util.exportExcel(list, "personalTranslate");
    }

    /**
     * 获取翻译工具详细信息
     */
    @PreAuthorize("@ss.hasPermi('amz:personalTranslate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(personalTranslateService.findById(id));
    }

    /**
     * 新增翻译工具
     */
    @PreAuthorize("@ss.hasPermi('amz:personalTranslate:add')")
    @Log(title = "翻译工具", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PersonalTranslate personalTranslate) {
        AjaxResult res = personalTranslateService.save(personalTranslate);
        return res;
    }

    /**
     * 修改翻译工具
     */
    @PreAuthorize("@ss.hasPermi('amz:personalTranslate:edit')")
    @Log(title = "翻译工具", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PersonalTranslate personalTranslate) {
        AjaxResult res = personalTranslateService.save(personalTranslate);
        return res;
    }

    /**
     * 删除翻译工具
     */
    @PreAuthorize("@ss.hasPermi('amz:personalTranslate:remove')")
    @Log(title = "翻译工具", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        personalTranslateService.deleteByIds(Arrays.asList(ids));
        return AjaxResult.success();
    }
}
